package com.anxin.act.config.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.anxin.framework.aspectj.lang.annotation.Excel;
import com.anxin.framework.web.entity.BaseEntity;

import java.util.List;

/**
 * 流程申请单对象 wf_apply_form
 *
 * @author 刘翔宇
 * @date 2020-03-13
 */
public class WfApplyForm extends BaseEntity<WfApplyForm>{
    private static final long serialVersionUID = 1L;

    /** 主键ID */
    private String id;

    /** 表单名称 */
    @Excel(name = "表单名称")
    private String name;

    /** 表单对应数据库表名 */
    @Excel(name = "表单对应数据库表名")
    private String tableName;

    /** 访问地址 */
    @Excel(name = "访问地址")
    private String path;


    private List<WfApplyFormField> wfApplyFormFieldList;

    public void setId(String id){
        this.id = id;
    }

    public String getId(){
        return id;
    }
    public void setName(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getPath(){
        return path;
    }

    public List<WfApplyFormField> getWfApplyFormFieldList() {
        return wfApplyFormFieldList;
    }

    public void setWfApplyFormFieldList(List<WfApplyFormField> wfApplyFormFieldList) {
        this.wfApplyFormFieldList = wfApplyFormFieldList;
    }

    /**
     * 将对象转为JSON
     * @return
     */
    public String toJson(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id",this.id);
        jsonObject.put("name",this.name);
        jsonObject.put("tableName",this.tableName);
        jsonObject.put("path",this.path);

        JSONArray fieldArray = new JSONArray();
        for (WfApplyFormField wfApplyFormField : wfApplyFormFieldList) {
            fieldArray.add(wfApplyFormField.toJson());
        }
        jsonObject.put("fieldArray",fieldArray);
        return jsonObject.toJSONString();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("name", getName())
            .append("table", getTableName())
            .append("path", getPath())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("delFlag", getDelFlag())
            .toString();
    }
}
